export const remove_current_node = function (snode) {
  const node = snode;
  if (this.get_editable()) {
    if (node.children && node.children.length) {
      snode.children.forEach((item) => {
        const copy = item;
        copy.data.props.parentid = snode.data.props.parentid;
        this.move_node(item, '_last_', snode.data.props.parentid);
      });
    }
    const nodeid = node.id;
    const parentid = node.parent.id;
    const parent_node = this.get_node(parentid);
    this.view.save_location(parent_node);
    this.view.remove_node(node);
    this.mind.remove_node(node);
    this.layout.layout();
    this.view.show(false);
    this.view.restore_location(parent_node);
    // this.invoke_event_handle(3, { evt: 'remove_node', data: [nodeid], node: parentid });
    return true;
  }
  return false;
};

export const options = () => ({
  container: 'jsmind_container',
  editable: true,
  theme: 'default',
  view: {
    draggable: true,
    line_color: 'rgba(24, 144, 255, 0.7)',
    line_style: 'straight',
  },
  menuOpts: {
    showMenu: true,
    tipContent: '这是啥',
    injectionList: [
      // {
      //   target: 'edit',
      //   text: '新建分支',
      //   callback(node) {
      //     console.log(1111);
      //   },
      // },
      // {
      //   target: 'addChild',
      //   text: '新建分支',
      //   callback(node) {
      //     console.log(211);
      //     // console.log(addNode(node));
      //     addNode(node);
      //   },
      // },
      // { target: 'addBrother', text: '添加兄弟节点' },
      // { target: 'delete', text: '删除节点' },
      // { target: 'showAll', text: '展开全部节点' },
      // { target: 'hideAll', text: '隐藏全部节点' },
      // { target: 'showNode', text: '展开选中的节点' },
      // { target: 'hideNode', text: '关闭选中的节点' },
    ],
  },
});

export const treeData = [
  {
    id: 'easy',
    topic: 'Easy',
    direction: 'left',
    expanded: false,
    children: [
      { id: 'easy1', topic: 'Easy to show' },
      { id: 'easy2', topic: 'Easy to edit' },
      { id: 'easy3', topic: 'Easy to store' },
      { id: 'easy4', topic: 'Easy to embed' },
    ],
  },
  {
    id: 'open',
    topic: 'Open Source',
    direction: 'right',
    expanded: true,
    children: [
      { id: 'open1', topic: 'on GitHub' },
      { id: 'open2', topic: 'BSD License' },
    ],
  },
  {
    id: 'powerful',
    topic: 'Powerful',
    direction: 'right',
    children: [
      { id: 'powerful1', topic: 'Base on Javascript' },
      { id: 'powerful2', topic: 'Base on HTML5' },
      { id: 'powerful3', topic: 'Depends on you' },
    ],
  },
  {
    id: 'other',
    topic: 'test node',
    direction: 'left',
    children: [
      { id: 'other1', topic: "I'm from local variable" },
      { id: 'other2', topic: 'I can do everything' },
    ],
  },
];

export const rootStyle = {
  'background-color': '#1890FF',
  'foreground-color': '#fff',
};

export const projectStyle = {
  'background-color': 'rgba(24, 144, 255, 0.7)',
  'foreground-color': '#fff',
};

// export const envStyle = {
//   'background-color': 'rgba(24, 144, 255, 0.05)',
//   'foreground-color': '#1890FF',
//   'font-weight': 700,
//   // border: '2px solid rgba(24, 144, 255, 0.7)',
// };

export const envStyle = {
  dev: '#9C8FFF',
  dev2: '#E68BFF',
  dev3: '#FF7676',
  dev4: '#FFAF36',
  sit: '#CBC0A1',
  uat: '#A9DC12',
  develop_experience: '#4ECEB3',
  develop_formal: '#28CBE4',
};

export const shadowStyle = {
  dev: '0px 0px 8px 0px rgba(156, 143, 255, 0.6)',
  dev2: '0px 0px 8px 0px rgba(230, 139, 255, 0.6)',
  dev3: '0px 0px 8px 0px rgba(255, 118, 118, 0.6)',
  dev4: '0px 0px 8px 0px rgba(255, 175, 54, 0.6)',
  sit: '0px 0px 8px 0px rgba(203, 192, 161, 0.8)',
  uat: '0px 0px 8px 0px rgba(169, 220, 18, 0.6)',
  develop_experience: '0px 0px 8px 0px rgba(78, 206, 179, 0.6)',
  develop_formal: '0px 0px 8px 0px rgba(40, 203, 228, 0.6)',
};

export const renderEnvStyle = (env) => {
  return {
    'background-color': envStyle[env] || 'rgba(24, 144, 255, 0.05)',
    'foreground-color': '#fff',
    'font-weight': 700,
    // 'background-color': 'rgba(24, 144, 255, 0.05)',
    // 'foreground-color': '#1890FF',
    // 'font-weight': 700,
    // border: '2px solid rgba(24, 144, 255, 0.7)',
  };
};

export const branchStyle = {
  'background-color': 'rgba(24, 144, 255, 0.05)',
  'foreground-color': '#1890FF',
  'font-weight': 400,
};

export const nameStyle = {
  'background-color': '#5eb2ff',
  'foreground-color': '#fff',
  'font-weight': 400,
  'font-size': '14px',
  // border: '1px solid rgba(24, 144, 255, 0.7)',
  'border-radius': '18px',
};

export const storyStyle = {
  'background-color': 'rgba(24, 144, 255, 0.05)',
  'foreground-color': '#1890FF',
  'font-weight': 700,
};

export const renderMind = (data) => ({
  meta: {
    name: 'jsMind-demo-tree',
    author: 'hizzgdev@163.com',
    version: '0.2',
  },
  format: 'node_array',
  data: [
    {
      id: 'root',
      isroot: true,
      topic: '前端环境使用记录',
      props: {
        level: 1,
      },
      ...rootStyle,
    },
    ...data,
  ],
});

export default {};
